package com.itheima.cotroller;

import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.sercive.checkGroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@Slf4j
@RequestMapping("/checkgroup")
public class InspectionTeamController {
    @Autowired
     private checkGroupService checkGroupService;
    /**
     * 新增检查组
     * @param checkGroup
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody CheckGroup checkGroup) {
        checkGroupService.add(checkGroup);
        return new Result(true, "新增成功");
    }
    /**
     * 删除检查组
     * @param id
     * @return
     */

    @DeleteMapping("/deleteById")
    public Result deleteById(@RequestParam Integer id) {
        checkGroupService.deleteById(id);
        return new Result(true, "删除成功");
    }
  /**
     * 分页查询
     * @param queryPageBean
     * @return
     */
    @GetMapping("/findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean) {
        List<CheckGroup> list = checkGroupService.findPage(queryPageBean.getQueryString());
        return new Result(true, "查询成功", list);
    }
    /**
     * 编辑检查组
     * @param checkitemIds
     * @param checkGroup
     * @return
     */
    @PutMapping("/edit")
    public Result edit(@RequestParam List<Integer> checkitemIds, @RequestBody CheckGroup checkGroup) {
        //根据id查询检查组
        CheckGroup checkGroup1 = checkGroupService.findById(checkGroup.getId());
        checkGroupService.update(checkGroup);
        return new Result(true, "编辑成功");
    }
   /**
     * 查询所有检查组
     * @return
     */
    @GetMapping("/findAll")
    public Result findAll() {
        List<CheckGroup> list = checkGroupService.findAll();
        return new Result(true, "查询成功", list);
    }

    /**
     *  根据检查组id查询检查项
     * @param id
     * @return
     */
    @GetMapping("/findById")
    public Result findById(@RequestParam Integer id) {
        CheckGroup checkGroup = checkGroupService.findById(id);
        return new Result(true, "查询成功", checkGroup);
    }
    /**
     * 根据检查组id查询检查项
     * @param setmealId
     * @return
     */
    @GetMapping("/findCheckGroupIdsBySetmealId")
    public Result findCheckGroupBySetmealId(@RequestParam Integer setmealId) {
        List<Integer> ids = checkGroupService.findCheckGroupBySetmealId(setmealId);
        return new Result(true, "查询成功", ids);
    }
}
